package com.public_module.tools;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {
    //时间戳变为日期
    public static String stampToDate(long s) {
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date(s);
        res = simpleDateFormat.format(date);
        return res;
    }

    public static String stampToDateTime(long s) {
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        Date date = new Date(s);
        res = simpleDateFormat.format(date);
        return res;
    }

    /* //日期转换为时间戳 */
    public static long timeToStamp(String timers) {
        Date d = new Date();
        long timeStemp = 0;
        try {
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
            d = sf.parse(timers);// 日期转换为时间戳
        } catch (Exception e) {
            e.printStackTrace();
        }
        timeStemp = d.getTime();
        return timeStemp;
    }
}
